
package com.sfzy.controller;

import com.sfzy.service.UserService;
import com.sfzy.entity.User;
import com.sfzy.util.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("add")
    public R addUser(@RequestBody User user) {
        return R.ok(userService.addUser(user));
    }

    @PutMapping
    public R updateUser(@RequestBody User user) {
        return R.ok(userService.updateUser(user));
    }

    @DeleteMapping("{id}")
    public R deleteUser(@PathVariable("id") int id) {
        return R.ok(userService.deleteUser(id));
    }

    @GetMapping("{id}")
    public R getUser(@PathVariable("id") int id) {
        return R.ok(userService.getUser(id));
    }

    @GetMapping("page")
    public R getUserPage(User user,
                         @RequestParam(defaultValue = "1",required = false) int pageNum,
                         @RequestParam(required=false,defaultValue="6") int pageSize) {
        return R.ok(userService.getUsers(user,pageNum,pageSize));
    }

}
